package com.zq.assistant.func.ioc.finder.method;

import com.zq.assistant.func.ioc.finder.cache.FindCache;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;

/**
 * Created by zhangqiang on 17-7-11.
 */

public class CachedMethodFinder extends BaseMethodFinder {

    private FindCache<Class,List<Method>> findCache;

    public CachedMethodFinder(Class<?> abortClass, FindCache<Class,List<Method>> findCache) {
        super(abortClass);
        this.findCache = findCache;
    }

    @Override
    public List<Method> findInjectMethod(Class targetClass, Class<? extends Annotation> annotationClass) {
        if(findCache != null){

            List<Method> methodList = findCache.get(targetClass);
            if(methodList != null){
                return methodList;
            }
        }

        List<Method> methodList = super.findInjectMethod(targetClass, annotationClass);
        if(methodList != null && findCache != null){

            findCache.put(targetClass,methodList);
        }
        return methodList;
    }
}
